package com.botu.content.controller;


import com.botu.content.dto.ResponseResult;
import com.botu.content.entity.Content;
import com.botu.content.service.IContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hanzeyao
 * @since 2020-02-15
 */
@RestController
@RequestMapping("/")
public class ContentController {

    @Autowired
    private IContentService contentService;

    /**
     * 获取所有资源
     * @return
     */
    @GetMapping("/")
    public ResponseResult<List<Content>> selectAll(){
        List<Content> contentList = contentService.selectAll();
        return new ResponseResult<>(200,"success",contentList);
    }

    @GetMapping("/view/{id}")
    public ResponseResult<Content> selectById(@PathVariable String id){
        Content content = contentService.seleceById(id);
        return new ResponseResult<>(200,"success",content);
    }

    /**
     * 未保护的资源 访问不需要经过授权
     * @return
     */
    @GetMapping("/get")
    public ResponseResult<List<Content>> getAll(){
        List<Content> contentList = contentService.selectAll();
        return new ResponseResult<>(200,"success",contentList);
    }
}
